package com.mvvm.ktnet.ext

import com.scwang.smart.refresh.layout.SmartRefreshLayout
import com.scwang.smart.refresh.layout.api.RefreshLayout

/**
 *
 * @ProjectName:    KtNet
 * @Package:        com.mvvm.ktnet.ext
 * @ClassName:      SmartRefreshLayoutExt
 * @Description:     java类作用描述
 * @Author:         Alex
 * @CreateDate:     2020/11/7 17:50
 * @UpdateUser:     更新者：
 * @UpdateDate:     2020/11/7 17:50
 * @UpdateRemark:   更新说明：
 * @Version:        1.0
 */
//初始化 SmartRefreshLayout
fun SmartRefreshLayout.refresh(block: RefreshLayout.() -> Unit): SmartRefreshLayout{
    this.run {
        setOnRefreshListener {
            finishRefresh(10000)
            block.invoke(it)
        }
    }
    return this
}

fun SmartRefreshLayout.loadmore(block: RefreshLayout.() -> Unit): SmartRefreshLayout {
    this.run {
        setOnLoadMoreListener {
            finishLoadMore(10000)
            block.invoke(it)
        }
    }
    return this
}


fun SmartRefreshLayout.refreshAndloadmore(
    refreshMy: RefreshLayout.() -> Unit = {},
    loadmoreMy: RefreshLayout.() -> Unit = {}
) {

    refresh {
        refreshMy.invoke(this)
    }
    loadmore {
        loadmoreMy.invoke(this)
    }

}


